package com.laiketui.order.controller;

import com.laiketui.core.domain.Result;
import com.laiketui.domain.user.User;
import com.laiketui.domain.vo.MainVo;
import com.laiketui.order.api.params.pay.BalancePayParams;
import com.laiketui.order.api.params.pay.BalanceRecordParams;
import com.laiketui.order.service.pay.BalancePayService;
import com.laiketui.root.annotation.HttpApiMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("balancePayController")
@RequestMapping("/balancePay/v2")
public class BalancePayController extends BaseController {

    @Autowired
    private BalancePayService balancePayService;



    @PostMapping("/pay")
    @HttpApiMethod(urlMapping = {"app.orderV2.balancePay"})
    public Result confirmOrder(BalancePayParams balancePayParams) {
        User user = getUser(balancePayParams);
        return Result.success(balancePayService.pay(balancePayParams,user.getUser_id(),user.getStore_id()));
    }

    @PostMapping("/balanceInfo")
    @HttpApiMethod(urlMapping = {"app.orderV2.balanceInfo"})
    public Result getUserInfo(MainVo vo) {
        User user = getUser(vo);
        return Result.success(balancePayService.getUserInfo(user));
    }

    @PostMapping("/balanceRecords")
    @HttpApiMethod(urlMapping = {"app.orderV2.balanceRecords"})
    public Result getBalanceRecords(BalanceRecordParams vo) {
        User user = getUser(vo);
        return Result.success(balancePayService.getBalanceRecords(user,vo));
    }

}
